package com.yswl.yeeduo.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.yswl.yeeduo.R;
import com.yswl.yeeduo.ui.bean.ActiviteDetailBean;
import com.yswl.yeeduo.ui.listener.AnimateFirstDisplayListener;
import com.yswl.yeeduo.ui.utils.ImageUtil;
import com.yswl.yeeduo.view.listview.BaseListViewAdapter;

public class LuckyAdapter extends BaseListViewAdapter<ActiviteDetailBean> {

	private LayoutInflater mInflater;
	protected ImageLoader imageLoader;
	protected DisplayImageOptions mOptions;
	private OnClickListener mListener;
	AnimateFirstDisplayListener mAnimalListener = new AnimateFirstDisplayListener();

	public LuckyAdapter(Context context, OnClickListener listener) {
		super(context);
		mInflater = LayoutInflater.from(context);
		mOptions = ImageUtil.getDefaultOptions();
		imageLoader = ImageLoader.getInstance();
		mListener = listener;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.luckymoney_list_item, null);
			viewHolder.pic = (ImageView) convertView.findViewById(R.id.lucky_img);
			viewHolder.lable = (Button) convertView.findViewById(R.id.activity_money_btn);
			viewHolder.title = (TextView) convertView.findViewById(R.id.title_tv);
			viewHolder.intru = (TextView) convertView.findViewById(R.id.desc_tv);
			viewHolder.shareIntru = (TextView) convertView.findViewById(R.id.specialnote_tv);
			viewHolder.readIntru = (TextView) convertView.findViewById(R.id.readnote_tv);
			viewHolder.bottom = (Button) convertView.findViewById(R.id.lucky_btn);

			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		ActiviteDetailBean beanData = getItem(position);
		// viewHolder.pic.setImageBitmap(imageLoader.loadImageSync(beanData.coverImg,
		// mOptions));
		imageLoader.displayImage(beanData.coverImg, viewHolder.pic, mOptions, mAnimalListener);
		viewHolder.title.setText(beanData.title);
		viewHolder.intru.setText("      " + beanData.describe);
		viewHolder.shareIntru.setText(beanData.specialNote);
		viewHolder.readIntru.setText(beanData.readReward);
		if (beanData.flag) {
			viewHolder.lable.setText(beanData.OrderMoney);
			viewHolder.lable.setBackgroundResource(R.drawable.selector_btn_hongbao);
			viewHolder.bottom.setBackgroundResource(R.drawable.selector_reg_btn);
			viewHolder.bottom.setText("查看排行榜");
//			viewHolder.bottom.setBackgroundResource(R.drawable.selector_btn_goranklist);
		} else {
//			viewHolder.bottom.setBackgroundResource(R.drawable.selector_btn_share);
			viewHolder.bottom.setBackgroundResource(R.drawable.selector_reg_btn);
			viewHolder.bottom.setText("分享拿红包");
			if (beanData.redflag) {
				viewHolder.lable.setText("?");
				viewHolder.lable.setBackgroundResource(R.drawable.selector_btn_hongbao);
			} else {
				viewHolder.lable.setBackgroundResource(R.drawable.img_redpackspented);
				viewHolder.bottom.setText("分  享");
			}
		}
		viewHolder.bottom.setTag(position);
		viewHolder.bottom.setOnClickListener(mListener);

		return convertView;
	}

	private static class ViewHolder {
		public ImageView pic;
		public Button lable;
		public TextView intru;
		public TextView title;
		public TextView shareIntru;
		public TextView readIntru;
		public Button bottom;
	}

}
